package com.atgm.mall.gmmailproduct.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atgm.mall.gmmailproduct.entity.AttrEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atgm.mall.gmmailproduct.entity.AttrAttrgroupRelationEntity;
import com.atgm.mall.gmmailproduct.service.AttrAttrgroupRelationService;
import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.R;



/**
 * 属性&属性分组关联
 *
 * @author pdx
 * @email 945097967@qq.com
 * @date 2021-08-20 09:07:21
 */
@RestController
@RequestMapping("gmmallproduct/attrattrgrouprelation")
public class AttrAttrgroupRelationController {

    @Autowired
    private AttrAttrgroupRelationService attrAttrgroupRelationService;

    /**
     * 根据分组id获取关联属性信息
     * @param attrGroupId
     * @return
     */
    @GetMapping("/attrInfo/{attr_group_id}")
    public R getAttrInfo(@PathVariable("attr_group_id") Long attrGroupId) {
        List<AttrEntity> list = attrAttrgroupRelationService.queryAttrInfo(attrGroupId);
        return R.ok().setData(list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAttrgroupRelationService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    @GetMapping("/addRela")
    public R addRale(@RequestParam("ids") List<Long> attrIds, @RequestParam("groupId") Long attrGroupId) {
        attrAttrgroupRelationService.addAttrAttrGroupRela(attrIds, attrGroupId);
        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.save(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
